package com.itheima.dao.impl;

import com.itheima.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDaoImpl implements AccountDao {

    //注入JdbcTemplate
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void out(String outName, int money) {

        System.out.println("转出开始了");

        String sql = "update tal_account set money = money - ? where username = ?";

        Object[] params = {money,outName};

        int count = jdbcTemplate.update(sql, params);

        System.out.println(count);

    }

    @Override
    public void in(String inName, int money) {

        System.out.println("转入开始了");

        String sql = "update tal_account set money = money + ? where username = ?";

        Object[] params = {money,inName};

        int count = jdbcTemplate.update(sql, params);

        System.out.println(count);
    }
}
